from django.db import models
from dingxiang.utils.models import BaseModel

from SearchHospital.models import HospitalModel
from disease.models import DepartmentModel

# 医生简介
class DoctorModel(BaseModel):
    doctor_name = models.CharField(max_length=255, null=True, verbose_name="姓名")
    rating = models.DecimalField(max_digits=8, decimal_places=2, null=True, verbose_name="评分")
    price = models.DecimalField(max_digits=10, decimal_places=2, null=True, verbose_name="价格")
    proficient_direction = models.CharField(max_length=100, null=True, blank=True, verbose_name="擅长方向")
    doctor_pictures = models.ImageField(upload_to='doctor/', null=True, blank=True, default='', verbose_name="医生图片")
    doctor_title = models.CharField(max_length=100, null=True, verbose_name="职称")
    doctor_specialty = models.CharField(max_length=100, null=True, verbose_name="个人简介")
    education_background = models.TextField(default="", blank=True, null=True, verbose_name="专业资历")
    practice_experience = models.TextField(default="", blank=True, null=True, verbose_name="执业经历")
    academic_achievements = models.TextField(default="", blank=True, null=True, verbose_name="学术经历")
    hospital = models.ForeignKey(HospitalModel, null=True, related_name="doctor_hospital", on_delete=models.DO_NOTHING, verbose_name="所属医院")
    recommend_home = models.BooleanField(default=False,verbose_name='是否推荐首页栏目', null=True)

    class Meta:
        db_table = 'doctor_introduction'
        verbose_name_plural = '医生简介'

    def __str__(self):
        return self.doctor_name

# 患者简介
class PatientProfile(models.Model):
    name = models.CharField(max_length=255, verbose_name="患者姓名")
    patient_pictures = models.ImageField(upload_to='patient/', null=True, blank=True, default='', verbose_name="患者图片")
    gender = models.CharField(max_length=10, choices=(('male', '男'), ('female', '女')), verbose_name="患者性别")
    birth_date = models.DateField(auto_now_add=True, null=True, blank=True, verbose_name="出生日期")
    age = models.IntegerField(null=True, blank=True, verbose_name="患者年龄")
    contact_number = models.CharField(max_length=20, verbose_name="联系方式")
    address = models.CharField(max_length=255, verbose_name="患者地址")
    id_number = models.CharField(max_length=18, verbose_name="身份证号")
    insurance_info = models.CharField(max_length=255, null=True, blank=True, verbose_name="医保信息")
    emergency_contact = models.CharField(max_length=255, verbose_name="紧急联系人")
    weight = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="患者体重")
    height = models.DecimalField(max_digits=5, decimal_places=2, verbose_name="患者身高")
    blood_type = models.CharField(max_length=5, verbose_name="血液类型")

    class Meta:
        db_table = 'patient_profile'
        verbose_name_plural = '患者简介'

    def __str__(self):
        return self.name  

# 医患问答
class DoctorPatientModel(BaseModel):
    question = models.TextField(default="", blank=True, null=True, verbose_name="问题")
    answer = models.TextField(default="", blank=True, null=True, verbose_name="回答")
    date = models.DateField(auto_now_add=True, verbose_name="日期")
    patient = models.ForeignKey(PatientProfile, related_name="patient_doctor_list", null=True, blank=True, on_delete=models.DO_NOTHING, verbose_name="患者")
    doctor = models.ForeignKey(DoctorModel, related_name="doctor_patient_list", null=True, blank=True, on_delete=models.DO_NOTHING, verbose_name="医生")
    recommend_home = models.BooleanField(default=False,verbose_name='是否推荐首页栏目', null=True)

    class Meta:
        db_table = 'doctor_patient'
        verbose_name_plural = '医患问答'
    def __str__(self):
        return f"{self.answer} - {self.question}"

# 患者评价
class PatientReviewModel(BaseModel):
    content = models.TextField(default="", blank=True, null=True, verbose_name="评价内容")
    rating = models.IntegerField(verbose_name="评分")
    # review_date = models.DateField(auto_now_add=True, verbose_name="评价时间")
    patient = models.ForeignKey(PatientProfile, related_name="patient_doctor_review_list", null=True, blank=True, on_delete=models.DO_NOTHING, verbose_name="患者")
    doctor = models.ForeignKey(DoctorModel, related_name="doctor_patient_review_list", null=True, blank=True, on_delete=models.DO_NOTHING, verbose_name="医生")

    class Meta:
        db_table = 'patient_review'
        verbose_name_plural = '患者评价'

    def __str__(self):
        return  self.content


# 问医生分类
class AskDoctorClassificationModel(BaseModel):
    classification_name = models.CharField(max_length=100, null=True, verbose_name='分类')

    class Meta:
        db_table = 'ask_doctor_classification'
        verbose_name_plural = '问医生分类'
    def __str__(self):
        return self.classification_name

# 问医生科室
class AskDoctorDepartmentModel(BaseModel):
    askDoctor_department = models.CharField(max_length=100, null=True, blank=True, verbose_name='科室')
    introduction = models.ManyToManyField(DoctorModel, null=True, blank=True, related_name="doctor_introduction", verbose_name="医生简介")
    askDoctor_classification = models.ManyToManyField(AskDoctorClassificationModel, null=True, blank=True, related_name="classification_department", verbose_name="问医生分类")
    def __str__(self):
        return self.askDoctor_department
    class Meta:
        db_table = 'ask_doctor_department'
        verbose_name_plural = '问医生科室'

    
